package Pokero;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JTextPane;

public class WymianaFrame extends JFrame implements ActionListener, ItemListener {
        
        private JFrame frame;
        private JTextPane text;
        private JButton exit;
        private JButton apply;
        private JCheckBox box1;
        private JCheckBox box2;
        private JCheckBox box3;
        private JCheckBox box4;
        private JCheckBox box5;
        private int Selected = 0;
        
        public WymianaFrame() {
                
                //okno
                super("Wymiana");
                frame = new JFrame();
                setVisible(true);
                setSize(400,200);
                setLayout(new FlowLayout());
                setLocationRelativeTo(null);
                setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                
                
                //exit
                exit = new JButton("Wyjscie");
                apply = new JButton("Zatwierdz");
                
                exit.addActionListener(this);
                apply.addActionListener(this);
                
                add(exit);
                add(apply);
                
                
                //text
                Font f = new Font(Font.SANS_SERIF, 5, 17);
                text = new JTextPane();
                text.setVisible(true);
                text.setText("Podaj numery kart do wymiany(max 4):    ");               
                text.setEditable(false);
                text.setBackground(null);
                text.setFont(f);
                
                add(text);
                
                
                //check boxy
                box1 = new JCheckBox("1");
                box2 = new JCheckBox("2");
                box3 = new JCheckBox("3");
                box4 = new JCheckBox("4");
                box5 = new JCheckBox("5");
                
                box1.addItemListener(this);
                box2.addItemListener(this);
                box3.addItemListener(this);
                box4.addItemListener(this);
                box5.addItemListener(this);
                                
                add(box1);
                add(box2);
                add(box3);
                add(box4);
                add(box5);
                
              //blokada rozmiaru okna
                this.addComponentListener(new ComponentAdapter(){
            public void componentResized(ComponentEvent e){
                Dimension d=WymianaFrame.this.getSize();
                if(d.width != 400)
                    d.width=400;
                if(d.height != 200)
                    d.height=200;
                WymianaFrame.this.setSize(d);
            }
        });
        }

        @Override
        public void actionPerformed(ActionEvent e) {
                Object source = e.getSource();
                
                if(source == exit) {
                        dispose();
                }
                if(source == apply)
                {
                        if(box1.isSelected())
                        {
                        	PlayerFrame.HumanPlayers[PokerFrame.PlayerBuffer].Hand[0] = Deck.wybierz();
                        	Selected +=1;
                        }
                        if(box2.isSelected())
                        {
                        	PlayerFrame.HumanPlayers[PokerFrame.PlayerBuffer].Hand[1] = Deck.wybierz();
                        	Selected +=1;
                        }
                        if(box3.isSelected())
                        {
                        	PlayerFrame.HumanPlayers[PokerFrame.PlayerBuffer].Hand[2] = Deck.wybierz();
                        	Selected +=1;
                        }
                        if(box4.isSelected())
                        {
                        	PlayerFrame.HumanPlayers[PokerFrame.PlayerBuffer].Hand[3] = Deck.wybierz();
                        	Selected +=1;
                        }
                        if(box5.isSelected())
                        {
                        	PlayerFrame.HumanPlayers[PokerFrame.PlayerBuffer].Hand[4] = Deck.wybierz();
                        	Selected +=1;
                        }
                        PokerFrame.HumCards(PokerFrame.PlayerBuffer);
                        PokerFrame.wymiana.setVisible(false);
                        dispose();
                }
                
        }

		@Override
		public void itemStateChanged(ItemEvent e) {
			Object source = e.getSource();
			
			if(box1.isSelected() && box2.isSelected() && box3.isSelected() && box4.isSelected()) {
				box5.setEnabled(false);
			}
			else
				box5.setEnabled(true);
			if(box1.isSelected() && box2.isSelected() && box3.isSelected() && box5.isSelected()) {
				box4.setEnabled(false);
			}
			else
				box4.setEnabled(true);
			if(box1.isSelected() && box2.isSelected() && box4.isSelected() && box5.isSelected()) {
				box3.setEnabled(false);
			}
			else
				box3.setEnabled(true);
			if(box1.isSelected() && box3.isSelected() && box4.isSelected() && box5.isSelected()) {
				box2.setEnabled(false);
			}
			else
				box2.setEnabled(true);
			if(box2.isSelected() && box3.isSelected() && box4.isSelected() && box5.isSelected()) {
				box1.setEnabled(false);
			}
			else
				box1.setEnabled(true);
			
		}
}